__author__ = 'Administrator'
import os,sys
class OprateFile(object):
    def __init__(self, file, method='wb+'):
        self.file = file
        self.method = method
        self.fileHandle = None

    def write_txt(self, text):
       if  os.path.isfile(self.file):
       #      self.fileHandle = open(self.file, "wb+")
       #      self.fileHandle.write(bytes("aaaaaaa" +"\n", 'UTF-8'))
       #      print("---------"+text)
       #      print("---------"+self.file)
       #      print("---------"+self.method)
           with open(r"d:\\appium\\temp\\report.txt", "wb+") as outfile:
                outfile.write(bytes("111111","utf-8"))
                print("111111")
                # for i in dict_list:
                #     self.fileHandle.write(i + "\n")
                # self.fileHandle.close()
       else:
            print('文件不存在' + self.file)

    def read_txt_row(self):
        if  os.path.isfile(self.file):
            self.fileHandle = open(self.file, self.method)
            print(self.fileHandle.readline())
            self.fileHandle.close()
        else:
             print('文件不存在' + self.file)

    def read_txt_rows(self, list_data={"data":[]}):
        if  os.path.isfile(self.file):
            self.fileHandle = open(self.file, self.method)
            file_list = self.fileHandle.readlines()
            for i in file_list:
                # print(i.strip("\n"))
                list_data["data"].append(eval(i))
                print(eval(i))
            self.fileHandle.close()
        else:
            print('文件不存在' + self.file)
        return list_data
    def check_file(self):
        if  os.path.isfile(self.file):
            print('文件不存在' + self.file)
            sys.exit()
        # print("文件存在！")
    def mkdir_file(self):
        if not os.path.isfile(self.file):
            f = open(self.file, self.method)
            f.close()
            print("----------创建文件成功")
        else:
            print("-------------文件已经存在")
    def remove_file(self):
        if os.path.isfile(self.file):
            os.remove(self.file)
            print("删除文件成功")
        else:
            print("文件不存在")